/**
 * 
 */
package com.alkandros.linesmash.adapter;

import hu.accedo.commons.logging.L;
import hu.accedo.commons.widgets.AsyncImageView;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.alkandros.linesmash.R;
import com.alkandros.linesmash.models.Restaurant;

/**
 * @author Jiju Induchoodan
 *
 */
public class RestaurantAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<Restaurant> array;
	private LayoutInflater inflater;
	
	public RestaurantAdapter(Context ctx,ArrayList<Restaurant> modelArray)
	{
		context  =  ctx;
		array	 =  modelArray;
		inflater =  LayoutInflater.from(context);
	}
	
	static class ViewHolder {
	    TextView txtName;
	    RatingBar ratingBar;
	    AsyncImageView imageView;
	}
	@Override
	public int getCount() {
		return array.size();
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		 	View rowView = convertView;
			final Restaurant model  = (Restaurant) this.getItem(position);
			if (rowView == null)
			{
				ViewHolder viewHolder 			= new ViewHolder();
				rowView 						= inflater.inflate(R.layout.restaurant_list_item, null);
				
				viewHolder.imageView			=(AsyncImageView)rowView.findViewById(R.id.img_item);
				viewHolder.txtName				=(TextView)rowView.findViewById(R.id.txt_name);
				viewHolder.ratingBar			=(RatingBar)rowView.findViewById(R.id.rating_bar);
				rowView.setTag(viewHolder);
			} 
			 ViewHolder holder = (ViewHolder) rowView.getTag();
			 
			// holder.imgBrand.setImageResource(model.getImage());
			 
			 L.e("Image ur"+model.getImage());
			 holder.imageView.setUrl(model.getImage());
			 holder.ratingBar.setRating(model.getRating());
			 holder.txtName.setText(model.getTitle());
		
		return rowView;
	}

}
